package com.engine4cloud.tdf.supervision.controller.web;

import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.data.web.response.PageInfo;
import com.engine4cloud.tdf.common.data.web.response.Params;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.supervision.dto.create.DcpgAuditAssignCreateDTO;
import com.engine4cloud.tdf.supervision.dto.create.DcpgAuditCreateDTO;
import com.engine4cloud.tdf.supervision.dto.create.DcpgCountyAuditCreateDTO;
import com.engine4cloud.tdf.supervision.dto.query.DcpgAuditQueryDTO;
import com.engine4cloud.tdf.supervision.dto.result.DcpgAuditResultDTO;
import com.engine4cloud.tdf.supervision.dto.result.EnumsTypeResultDTO;
import com.engine4cloud.tdf.supervision.service.DcpgAuditResultService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 调查评估-审核-web
 *
 * @author pig
 * @date 2024-02-29 11:13:01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/investigation/audit")
@Tag(description = "InvestigationAuditWeb", name = "调查评估-审核-web")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class DcpgAuditResultWebController {

    private final DcpgAuditResultService dcpgAuditResultService;

    /**
     * 状态列表
     */
    @Operation(summary = "状态列表", description = "状态列表")
    @GetMapping("/all/status")
    public R<List<EnumsTypeResultDTO>> status() {
        return R.ok(dcpgAuditResultService.status());
    }

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param dto  调查评估审核-审核
     * @return R<PageInfo < DcpgAuditResultDTO>>
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    public R<PageInfo<DcpgAuditResultDTO>> getAuditResultPage(@ParameterObject Params page, @Valid @ParameterObject DcpgAuditQueryDTO dto) {
        return R.ok(dcpgAuditResultService.pageList(page, dto));
    }


    /**
     * 通过id查询调查评估-审核
     *
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}")
    public R<DcpgAuditResultDTO> getById(@PathVariable("id") Long id) {
        return R.ok(dcpgAuditResultService.getById(id));
    }

    /**
     * 流程审核详情
     *
     * @param code 调查评估编号
     * @return R
     */
    @Operation(summary = "流程审核详情", description = "流程审核详情")
    @GetMapping("/list")
    public R<List<DcpgAuditResultDTO>> getListByCode(@Schema(description = "调查评估编号") @ParameterObject String code) {
        return R.ok(dcpgAuditResultService.getListByCode(code));
    }

    /**
     * 县指派
     */
    @Operation(summary = "县指派", description = "县指派")
    @SysLog("县指派")
    @PutMapping("/assign")
    @PreAuthorize("@pms.hasPermission('investigation_assign')")
    public R<Boolean> assign(@Valid @RequestBody DcpgAuditAssignCreateDTO dto) {
        return R.ok(dcpgAuditResultService.assign(dto));
    }

    /**
     * 所接收
     */
    @Operation(summary = "所接收", description = "所接收")
    @SysLog("所接收")
    @PutMapping("/accept")
    @PreAuthorize("@pms.hasPermission('investigation_accept')")
    public R<Boolean> accept(@Valid @RequestBody DcpgAuditCreateDTO dto) {
        return R.ok(dcpgAuditResultService.accept(dto));
    }

    /**
     * 所拒绝
     */
    @Operation(summary = "所拒绝", description = "所拒绝")
    @SysLog("所拒绝")
    @PutMapping("/refuse")
    @PreAuthorize("@pms.hasPermission('investigation_refuse')")
    public R<Boolean> refuse(@Valid @RequestBody DcpgAuditCreateDTO dto) {
        return R.ok(dcpgAuditResultService.refuse(dto));
    }

    /**
     * 所提交
     */
    @Operation(summary = "所提交", description = "所提交")
    @SysLog("所提交")
    @PutMapping("/submit")
    @PreAuthorize("@pms.hasPermission('investigation_submit')")
    public R<Boolean> submit(@Valid @RequestBody DcpgAuditCreateDTO dto) {
        return R.ok(dcpgAuditResultService.submit(dto));
    }

    /**
     * 县审核（通过或拒绝）
     */
    @Operation(summary = "县审核", description = "县审核")
    @SysLog("县审核")
    @PutMapping("/audit")
    @PreAuthorize("@pms.hasPermission('investigation_audit')")
    public R<Boolean> audit(@Valid @RequestBody DcpgCountyAuditCreateDTO dto) {
        return R.ok(dcpgAuditResultService.audit(dto));
    }
}